package com.msk.web.controller.wlhy.goods;

import com.msk.common.core.controller.BaseController;
import com.msk.common.core.domain.R;
import com.msk.common.core.domain.model.LoginUser;
import com.msk.common.utils.StringUtils;
import com.msk.framework.web.utils.TokenUtils;
import com.msk.wlhy.domain.HtTransportDetail;
import com.msk.wlhy.service.HtTransportDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author llh
 * @date 2023/6/20
 * @description 货主运单管理在途运单
 */
@Api(tags = "运单管理")
@RestController
@RequestMapping("/api/transportDetail")
public class HtTransportDetailController extends BaseController {
    
    @Autowired
    private HtTransportDetailService htTransportDetailService;
    
    /**
     * @author llh
     * @date 2023/6/20
     * @return com.msk.common.core.domain.R<?>
     * @description 货主在途运单列表      
     */
    @ApiOperation("货主在途运单列表")
    @PostMapping("/goodsTransportList")
    public R<?> goodsTransportList(@RequestBody HtTransportDetail htTransportDetail){
        LoginUser loginUser = TokenUtils.getMpLoginUser();
        if(loginUser != null){
            htTransportDetail.setDriverId(loginUser.getLoginId());
        }
        htTransportDetail.getParams().put("orderByStr", "a.create_date desc");
        startPageJson(htTransportDetail.getParams(),"");
        List<Map<String,Object>> list = htTransportDetailService.findGoodsWayBillList(htTransportDetail);
        return R.appOk(getDataTable(list));
    }
    
    /**
     * @author llh
     * @date 2023/6/20
     * @return com.msk.common.core.domain.R<?>
     * @description 货主在途运单详情      
     */
    @ApiOperation("货主在途运单详情")
    @PostMapping("/getTransitWayBillInfo")
    public R<?> getTransitWayBillInfo(@RequestBody Map<String,String> params){
        String id = params.get("id");
        if(StringUtils.isEmpty(id)){
            return R.appFail(400101,"运单ID为空");
        }
        HtTransportDetail htTransportDetail = htTransportDetailService.getGoodsWayBillInfo(id);
        return R.appOk(htTransportDetail);
    }
}
